package com.overseasShopping.Base.DAOImpl;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.overseasShopping.Base.DAO.BaseDAO;
import com.overseasShopping.util.ListUtil;

public class BaseDAOImpl<T> extends HibernateDaoSupport implements BaseDAO<T>{
	
	private Class<T> entityClass;
	public BaseDAOImpl(){
		try{
			Type[] typeArr=((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments();
			if(typeArr!=null&&typeArr.length>0){
				entityClass=(Class<T>)typeArr[0];
			}
		}catch (Exception e) {
			throw new RuntimeException("没有给T指定类型");		
		}
	}
	public void save(T t) {
		getHibernateTemplate().save(t);
		
	}

	public void delete(T t) {
		getHibernateTemplate().delete(t);
		
	}

	public void update(T t) {
		getHibernateTemplate().update(t);
		
	}

	public T get(Serializable id) {
		return (T)getHibernateTemplate().get(entityClass, id);
	}

	public List<T> getAll() {
		return getHibernateTemplate().loadAll(entityClass);
	}

}
